package com.igeek.blog_parent_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.blog_parent_test.entity.Articles;
import com.igeek.blog_parent_test.mapper.ArticlesMapper;
import com.igeek.blog_parent_test.service.IArticlesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.blog_parent_test.vo.PageQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-04
 */
@Service
public class ArticlesServiceImpl extends ServiceImpl<ArticlesMapper, Articles> implements IArticlesService {

    @Transactional(readOnly = true)
    @Override
    public Page<Articles> findPage(PageQueryVO vo) {
        Integer currentPage = vo.getCurrentPage();
        Integer pageSize = vo.getPageSize();
        Page<Articles> page = Page.of(currentPage, pageSize);

        String queryString = vo.getQueryString();
        LambdaQueryWrapper<Articles> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.hasLength(queryString),Articles::getArticleId,queryString)
                .or()
                .like(StringUtils.hasLength(queryString),Articles::getTitle,queryString);
        Page<Articles> articlesPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return articlesPage;
    }

    @Override
    public boolean del(Integer articleId) {
        return false;
    }
}
